//
//  FYVersionManager.m
//  MockProject
//
//  Created by FanYu on 8/20/16.
//  Copyright © 2016 niuzhaowang. All rights reserved.
//

#import "YXVersionManager.h"
#import "YXTabbarController.h"
#import "YXIntroViewController.h"
#import "YXUserDefault.h"
#import "YXTaskManager.h"


@implementation YXVersionManager

+ (void)selectRootViewController {
    NSString *lastVersion = [YXUserDefault lastVersion];
    
    // current version from system
    NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    
    // save version
    if ([currentVersion isEqualToString:lastVersion]) {
        YXTabbarController *tabBarController = [[YXTabbarController alloc] init];
        keyWindow.rootViewController = tabBarController;
        
    }
    // new version
    else {
        // first time login
        if (![YXUserDefault maxSimultaneouslyNumber]) {
            [YXUserDefault setMaxSimultaneouslyNumber:@"3"];
            [YXUserDefault setOnlyDownloadOnWiFi:YES];
        }
        
        // load date
        [YXTaskManager loadTaskToDB];
        
        YXIntroViewController *intro = [[YXIntroViewController alloc] init];
        keyWindow.rootViewController = intro;
        [YXUserDefault setCurrentVersion:currentVersion];
    }
}

@end


